<template>
  <div class="view-container zi-chan-list">
    <header class="view-header">
      <div class="header-container">
        <div class="header-title">
          <i class="el-icon-s-grid"></i>
          <span>资产购置</span>
        </div>
        <div class="header-form">
          <!--更多-->
          <!--<div class="header-form-item">
            <el-dropdown @command="handleCommand">
              <el-button type="default" :loading="delLoading">
                更多<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item icon="el-icon-refresh-right" class="color-refresh-item" command="refresh">刷新
                </el-dropdown-item>
                <el-dropdown-item icon="el-icon-edit" class="color-edit-item" command="edit">编辑</el-dropdown-item>
                <el-dropdown-item icon="el-icon-delete" class="color-del-item" command="del">{{isBatchesDel}}
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>-->
          <div class="header-form-item">
            <el-button icon="el-icon-refresh-right" @click="refresh">刷新</el-button>
          </div>
          <div class="header-form-item">
            <el-button icon="el-icon-edit" @click="openEditDialog(true)">编辑</el-button>
          </div>
          <div class="header-form-item">
            <el-button type="danger" :loading="delLoading" icon="el-icon-delete" @click="del">{{isBatchesDel}}</el-button>
          </div>
          <!--搜索-->
          <div class="header-form-item">
            <el-button type="primary" icon="el-icon-search" @click="fetchData">查询</el-button>
          </div>
          <div class="header-form-item">
            <el-button type="success" icon="el-icon-notebook-2" @click="openEditDialog(false)">购置申请</el-button>
          </div>
        </div>
      </div>
    </header>

    <section>
      <el-table
        ref="table"
        :data="tableData"
        border
        stripe
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
      >
        <el-table-column type="selection" align="center"/>
        <el-table-column prop="departmentName" label="申请部室" align="center" width="150" />
        <el-table-column label="资产名称" align="left" >
          <template slot-scope="s">
            <el-link @click="showDetail(s.row.zgId)">{{s.row.ziChanMingCheng}}</el-link>
          </template>
        </el-table-column>
        <el-table-column sortable prop="yuSuanJinE" label="预算金额" width="150" align="center"/>
        <el-table-column sortable prop="zgtime" label="申请时间" :formatter="zgtimeFmt" width="150" align="center"/>
        <el-table-column sortable prop="stateName" label="状态" width="100" align="center">
          <template slot-scope="s">
            <el-tag :type="switchType(s.row.stateName)">{{s.row.stateName}}</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </section>
    <footer>
      <el-pagination
        :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
        :page-size="page.size"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </footer>

    <zi-chan-save ref="save-page" @update="update"></zi-chan-save>
  </div>
</template>

<script>
  import ziChanAPI from '@/api/ziChan/ziChan'
  import ZiChanSave from './ZiChanSave'
  import listMixin from '@/mixin/listMixin'
  import flowManagerListMixin from '@/mixin/flowManagerListMixin'
  export default {
    name: 'ZiChanList',
    components:{ZiChanSave},
    mixins: [listMixin,flowManagerListMixin],
    data() {
      return {
        mixinParams: {
          addUrl: '',
          editUrl: '',
          propertyName: 'zgId',
          API: ziChanAPI
        },
      }
    },
    created() {
    },
    computed: {
    },
    methods: {
      showDetail(id){
        this.$router.push('/zichan/approval-detail/'+id+'/'+false)
      },
      update(){
        this.fetchData()
      },
      fetchData() {
        ziChanAPI.list(this.page).then(res => {
          console.log(res)
          this.tableData = res.records
          this.page.total = res.total
        })
      },
      zgtimeFmt(row){
        return this._util.format(row.zgtime)
      }
    }
  }
</script>

<style lang="scss">

  .zi-chan-list {
    .el-dialog {
      width: 40%;
      .el-dialog__footer {
          padding: 10px 45px;
      }
    }
  }

</style>

